<?php
class ModelLocalisationZone extends Model {
	public function getZone($zone_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int)$zone_id . "' AND status = '1'");

		return $query->row;
	}

	public function getZonesByCountryPost($postcode) {
		$zone_data = $this->cache->get('zone.' . (int)$postcode);

		 if (!$zone_data) {
			$query = $this->db->query("SELECT z.`name`,z.zone_id,c.country_id,c.`name` as parent_name FROM " . DB_PREFIX . "zone z LEFT JOIN " . DB_PREFIX . "country c ON c.country_id=z.country_id WHERE post_code = '" . (int)$postcode . "' AND z.status = '1' ORDER BY z.zone_id");

			$zone_data = $query->rows;

			$this->cache->set('zone.' . (int)$postcode, $zone_data);
		}
//      print_r("SELECT z.`name`,z.zone_id,c.country_id,c.`name` as parent_name FROM " . DB_PREFIX . "zone z LEFT JOIN " . DB_PREFIX . "country c ON c.country_id=z.country_id WHERE post_code = '" . (int)$postcode . "' AND z.status = '1' ORDER BY z.zone_id");
		// print_r($query->rows);
		return $zone_data;
	}
	
	public function getZonesByCountryId($country_id) {
		$zone_data = $this->cache->get('zone.' . (int)$country_id);

		if (!$zone_data) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE country_id = '" . (int)$country_id . "' AND status = '1' ORDER BY zone_id");

			$zone_data = $query->rows;

			$this->cache->set('zone.' . (int)$country_id, $zone_data);
		}

		return $zone_data;
	}
}